Ext.ns("FieldServiceDatabase");
FieldServiceDatabase.UploadWindow = Ext.extend(Ext.Window, {
    modal: true,
    id: 'upload-window',
    layout: 'fit',
    width: 300,
    height: 120,
    closeAction: 'hide',
    layout: 'fit',
    plain: true,
    title: 'Upload',
    initComponent: function(){
    
    
        var uploadButton = new Ext.Button({
            text: 'Upload',
            handler: function(){
				this.hide()
                if (fp.getForm().isValid()) {
                    fp.getForm().submit({
                        url: '/upload',
                        waitMsg: 'Uploading your photo...',
                        success: function(fp, o){
                            Ext.MessageBox.alert('Success', 'File uploaded to the server');
                        },
						failur: function(form, action){
							Ext.MessageBox.alert('Failure', 'Failed to upload file to the server. Please try again.')
						}
                    });
                }
            },
            scope: this
        });
        
        var fp = new Ext.FormPanel({
        
            fileUpload: true,
            width: 50,
            frame: true,
            
            labelWidth: 50,
            defaults: {
                anchor: '95%',
                allowBlank: false,
                msgTarget: 'side'
            },
            items: [{
                xtype: 'fileuploadfield',
                id: 'form-file',
                emptyText: 'Select a csv file',
                fieldLabel: 'CSV File',
                name: 'file',
                buttonText: '',
                buttonCfg: {
                    iconCls: 'upload-icon'
                }
            }, {
                xtype: 'textfield',
                name: 'file_type',
                value: 'csv',
                hidden: true
            }, {
                xtype: 'textfield',
                name: 'action',
                value: 'upload',
                hidden: true
            }],
            buttons: [uploadButton, {
                text: 'Reset',
                handler: function(){
                    fp.getForm().reset();
                }
            }]
        });
        
        
        
        
        this.upload_form = fp;
        
        
        Ext.apply(this, {
            items: fp
        });
        
        FieldServiceDatabase.UploadWindow.superclass.initComponent.call(this, arguments);
        
        
    }
    
});





